﻿<?xml version="1.0" encoding="utf-8"?>
<!-- Open XML Math (OMML to XAML)-->
<xsl:stylesheet version="1.0"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="msxsl">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="m:oMath">
    <xsl:comment>Math Paragraph</xsl:comment>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
      <xsl:apply-templates select="*"/>
    </StackPanel>
  </xsl:template>

  <xsl:template match="m:sSup">
    <xsl:apply-templates select="*"/>
  </xsl:template>

  <xsl:template match="m:e">
    <xsl:comment>Equation Element</xsl:comment>
    <StackPanel VerticalAlignment="Center">
      <xsl:apply-templates select="*"/>
    </StackPanel>
  </xsl:template>

  <xsl:template match="m:d">
    <StackPanel Orientation="Horizontal">
      <xsl:comment>Delimiter</xsl:comment>
      <TextBlock Text="("/>
      <xsl:apply-templates select="*"/>
      <TextBlock Text=")"/>
    </StackPanel>
  </xsl:template>

  <xsl:template match="m:sup">
    <xsl:comment>Superscript</xsl:comment>
    <TextBlock FontFamily="{m:r/w:rPr/w:rFonts/@w:ascii}" FontStyle="Italic" VerticalAlignment="Center" RenderTransformOrigin="0,0">
      <TextBlock.RenderTransform>
        <TransformGroup>
          <ScaleTransform ScaleX="0.75" ScaleY="0.75"/>
          <SkewTransform/>
          <RotateTransform/>
          <TranslateTransform Y="-2.5"/>
        </TransformGroup>
      </TextBlock.RenderTransform>
      <xsl:value-of select="m:r/m:t"/>
    </TextBlock>
  </xsl:template>

  <xsl:template match="m:r">
    <TextBlock Margin="2" FontFamily="{w:rPr/w:rFonts/@w:ascii}" VerticalAlignment="Center" >
      <xsl:value-of select="m:t"/>
    </TextBlock>
  </xsl:template>

  <xsl:template match="m:f">
    <xsl:comment>Fraction</xsl:comment>
    <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
      <Border BorderThickness="0,0,0,0.75" BorderBrush="Black">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
          <xsl:apply-templates select="m:num/*"/>
        </StackPanel>
      </Border>
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
        <xsl:apply-templates select="m:den/*"/>
      </StackPanel>
    </StackPanel>
  </xsl:template>

  <xsl:template match="m:t" mode="Math">
    <Run>
      <xsl:value-of select="text()"/>
    </Run>
  </xsl:template>
</xsl:stylesheet>
